import {
  isRef,
} from "vue";

export function isObject(value) {
  return typeof value === "object" && value != null;
}

export function mergeReactiveObject(target, partialState) {
  for (const key in partialState) {
    if (!Object.prototype.hasOwnProperty.call(partialState, key)) continue;
    const oldValue = target[key];
    const newValue = partialState[key];
    if (isObject(oldValue) && isObject(newValue) && isRef(newValue)) {
      target[key] = mergeReactiveObject(oldValue, newValue);
    } else {
      target[key] = newValue;
    }
  }
  return target;
}